use scraper::{Html, Selector};

fn main() {
    let html = r#"
    <!DOCTYPE html>
    <meta charset="utf-8">
    <div test="123" test2="456">Element with test attribute</div>
    <title id="222">Hello, world!</title>
    <h1 class="foo">Hello, <i>world!</i></h1>
"#;

    let document = Html::parse_document(html);

    // 获取test属性为123、test2属性为456的元素
    let selector = Selector::parse(r#"[test="123"][test2="456"]"#).unwrap();
    for element in document.select(&selector) {
        println!("Element with test=123: {}", element.inner_html());
    }

 // 获取id属性为222的元素
    let selector = Selector::parse(r#"[id="222"]"#).unwrap();
    for element in document.select(&selector) {
        println!("Element with id=222: {}", element.inner_html());
    }

 // 获取id属性为222的元素
    let selector = Selector::parse(r#"h1[class="foo"]"#).unwrap();
    for element in document.select(&selector) {
        println!("Element h1 with class=foo: {}", element.inner_html());
    }


}
